package com.jiang.daily.Q2506;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/02/22 13:37
 */
class Solution {
    public int similarPairs(String[] words) {
        int res = 0;
        Map<Integer, Integer> map = new HashMap<>();
        for (String word: words) {
            char[] arr = word.toCharArray();
            int state = 0;
            for (int i = 0; i < arr.length; i++) {
                state |= 1 << (arr[i] - 'a');
            }
            res += map.getOrDefault(state, 0);
            map.compute(state, (k, v) -> v != null ? v + 1 : 1);
        }
        return res;
    }
}
